// -----------------------------
// Author: 		Dhaenens Gert	
// Creation: 	9/22/2014 9:56:49 AM				
// -----------------------------

#include "Camera.h"

#include "Application.h"
#include "Window.h"

Camera::Camera(const TString& Name)
	: Actor(Name, Actor::Camera)
	, m_NearDistance(0.01f)
	, m_FarDistance(1000.0f)
	, m_Fov(Math::Deg2Rad(75.0f))
	, m_View()
	, m_Projection()
{
}

Camera::~Camera()
{
}

void Camera::Update(Application* lpApp, Float deltaTime)
{
	// Update the View Matrix
	Vector3 dir = GetForward();
	m_View = Matrix::LookAt(Vector4(m_Position, 1.0f), dir, Vector3::UnitY);

	// Update the Projection Matrix
	Float aspectRatio = ((Float)lpApp->GetWindow()->GetWidth() / (Float)lpApp->GetWindow()->GetHeight());
	m_Projection = Matrix::Perspective(m_Fov, aspectRatio, m_NearDistance, m_FarDistance);
}
void Camera::SetFov(Float fov)
{
	m_Fov = fov;
}
void Camera::SetNear(Float nearDist)
{
	m_NearDistance = nearDist;
}
void Camera::SetFar(Float farDist)
{
	m_FarDistance = farDist;
}

Matrix Camera::GetView() const
{
	return m_View;
}
Matrix Camera::GetProjection() const
{
	return m_Projection;
}
Float Camera::GetFov() const
{
	return m_Fov;
}
Float Camera::GetNear() const
{
	return m_NearDistance;
}
Float Camera::GetFar() const
{
	return m_FarDistance;
}